const express = require('express');
const jwt = require('express-jwt');
const app = express();
const cors = require('cors');


app.listen(3000,()=>console.log('服务器启动了'));

app.use(cors());
app.use(jwt({ algorithms: ['HS256'], secret: 'asdad'}).unless({path: ['/api/login','/api/reguser']}));

//配置请求体
app.use(express.urlencoded({extended:true}));

//登陆注册接口
app.use('/api',require('./Router/login'));

//用户信息接口
app.use('/my/user',require('./Router/user'));


//分类操作接口
app.use('/my/category',require('./Router/categeory'));

//文章操作接口
app.use('/my/article',require('./Router/article'));

//处理错误
app.use((err, req, res, next) => {
  
    if (err.name === 'UnauthorizedError') {
      // res.status(401).send('invalid token...');
      res.status(401).send({ status: 1, message: '身份认证失败！' });
    }   
  });